﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LOPA
{
    public partial class PSIPage : UserControl
    {   
        public PSIPage()
        {
            InitializeComponent();
            ShowCheckedPsiList();
        }

        private void btnEdit_Click(object sender, EventArgs e){
            tlpMain.Enabled = true;
        }

        private void ShowCheckedPsiList(){
            foreach (Control c in tlpMain.Controls){
                if(Program.Workspace.GetPsiList().Contains(c.Text)){
                    ((CheckBox) c).Checked = true;
                }
            }
        }

        public void btnSave_Click(object sender, EventArgs e){
            tlpMain.Enabled = false;
            List<string> list = new List<string>();
            foreach (Control c in tlpMain.Controls){
                if(((CheckBox)c).Checked){
                    list.Add(c.Text);
                }
            }
            Program.Workspace.SavePsiList(list);
            Program.Workspace.SaveProject(MainForm.mainForm.SaveFilePath);
            MessageBox.Show("PSI清单保存成功!");
        }

        public void SaveWithoutRemider(){
            tlpMain.Enabled = false;
            List<string> list = new List<string>();
            foreach (Control c in tlpMain.Controls)
            {
                if (((CheckBox)c).Checked)
                {
                    list.Add(c.Text);
                }
            }
            Program.Workspace.SavePsiList(list);
        }
    }
}
